package com.mars.miaosha.controller;

import com.mars.miaosha.domain.User;
import com.mars.miaosha.redis.RedisService;
import com.mars.miaosha.redis.UserKey;
import com.mars.miaosha.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author MARS
 * @date 2018/5/7
 */

@Controller
@RequestMapping("/redis")
public class RedisController {
    @Autowired
    RedisService redisService;

//    @RequestMapping("/get")
//    @ResponseBody
//    public Result<Long> redisGet() {
//        Long v1 = redisService.get("key1",Long.class);
//        return Result.success(v1);
//    }
//
//    @RequestMapping("/setAndGetString")
//    @ResponseBody
//    public Result<String> setAndGetString() {
//        boolean v1 = redisService.set("key2","hello,mars");
//        String str = redisService.get("key2",String.class);
//        return Result.success(str);
//    }

    @RequestMapping("/getUserKeyId")
    @ResponseBody
    public Result<User> getUserKeyId() {
        User user = redisService.get(UserKey.getById,""+1,User.class);
        return Result.success(user);
    }

    @RequestMapping("/setUser")
    @ResponseBody
    public Result<Boolean> setUser() {
        User user = new User();
        user.setId(1);
        user.setName("summer");
        redisService.set(UserKey.getById,""+1,user);
        return Result.success(true);
    }
}
